// pages/home/index.js
import QQMapWX from "../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk";
var qqmapsdk = new QQMapWX({
  key: 'KXGBZ-U7H36-ZD5S5-EOYGV-J7MXO-ZNBKS' // 必填
});
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight:wx.getMenuButtonBoundingClientRect().top + wx.getMenuButtonBoundingClientRect().height + "px",
    list:[],
    list1:[],
    list2:[],
    background: ['demo1', 'demo2', 'demo3','demo4'],
    bannerlist:[
      '/assets/images/icons/1.png',
      '/assets/images/icons/2.png',
      '/assets/images/icons/3.png',
      '/assets/images/icons/6.png'
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    swiperIndex:0,
    jinherifu:"d",
    city:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  change(e){
    var that = this
    that.setData({
        swiperIndex:e.detail.current
    })
  },
  init(){
    var that = this
    wx.request({
      url:"http://bufantec.com/api/douban/movie/in_theaters",
      success(res){
        console.log(res)
        that.setData({
            list:res.data.data.list
        })
      }
    })
    wx.request({
      url:"http://bufantec.com/api/douban/movie/coming_soon",
      success(res1){
        console.log(res1)
        that.setData({
            list1:res1.data.data.list
        })
      }
    })
    wx.request({
      url:"http://bufantec.com/api/douban/movie/selectPreview",
      success(res2){
        console.log(res2)
        that.setData({
            list2:res2.data.data
        })
      }
    })


  },
  onLoad: function (options) {
    this.init();
    qqmapsdk = new QQMapWX({
        key: 'ZCUBZ-RQY6U-NBCVZ-2YHHU-BHGZE-ONB7F' // 必填
    });  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  // getLocation(){
  //   wx.getLocation({
  //     success(res){
  //       console.log(res)
  //     }
  //   })
  // },
  onShow: function () {
    let that = this
    wx.getLocation({
      success(res){
        console.log(res)
        qqmapsdk.reverseGeocoder({
                location: `${res.latitude},${res.longitude}`,
                success(result){
                  console.log(result)
                  that.setData({
                     city:result.result.address_component.city
                  })
                }
              });
              qqmapsdk.search({
                keyword:"影院",
                location: `${res.latitude},${res.longitude}`,
                success(result){
                  console.log("定位周边信息",result)
                }
              })
      }
    })

    
    // var a = wx.getMenuButtonBoundingClientRect();
    // console.log(a)
    // wx.getLocation({
    //   success(res){
    //     console.log(res);
    //     qqmapsdk.reverseGeocoder({
    //       location: `${res.latitude},${res.longitude}`,
    //       success(result){
    //         console.log(result)
    //       }
    //     });
    //     qqmapsdk.search({
    //       keyword:"影院",
    //       location: `${res.latitude},${res.longitude}`,
    //       success(result){
    //         console.log("定位周边信息",result)
    //       }
    //     })
    //   }
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})